<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>在render中创建vModel</title>
  <script src="https://unpkg.com/vue@2"></script>
</head>
<body>
  <div id="app">
    <div class="wrap">
      <h5 class="title">input输入框</h5>
      <custom-input v-model="inputValue"></custom-input>
      <p class="preview">绑定值为: {{ inputValue }}</p>
    </div>
  </div>
</body>
<style>
  .wrap {
    background: #f3f3f3;
    padding: 10px;
    margin-bottom: 16px;
  }
  .wrap .title {
    margin: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid #ddd;
    line-height: 2;
    font-size: 14px;
  }
  .wrap .preview {
    font-size: 13px;
  }
</style>
<script>
  // 使用render函数实现v-model
 Vue.component('custom-input', {
  props: ['value'],
  render: function(createElement) {
    var self = this;
    return createElement('input', {
      domProps: {
        value: self.value,
      },
      on: {
        input: function(event) {
          self.$emit('input', event.target.value)
        }
      }
    })
  }
 })
 var app = new Vue({
  el: '#app',
  data() {
    return {
      inputValue: '',
    }
  },
  mounted() {
  }
 })
</script>
</html>
